using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Evolution.VirtualFileSystem;
using Evolution.Engine;
using Evolution.Engine.Utilities;

namespace Evolution.Utilities
{
    public class ResourceContent : ContentManager
    {
        private ResourceLibrary myLibrary = null;

        public ResourceContent(IServiceProvider serviceProvider)
            : base(serviceProvider)
        {
            myLibrary = new ResourceLibrary(Properties.Settings.Default.ResourceLibrary);
        }

        protected override System.IO.Stream OpenStream(string assetName)
        {
            string fileName = GameUtils.RelativeFileNameWithoutExtention(assetName);

            if( myLibrary != null )
                if (myLibrary.Contains(fileName))
                    return myLibrary.GetFile(fileName);

            return base.OpenStream(assetName);            
        }
    }
}
